/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor...
 */
package captchabuster;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author alexnewski
 */
public class CaptchaBuster {

    /**
     * @param args the command line arguments
     * this is a test
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {
        // TODO code application logic here

        List<String> classes = new ArrayList<String>();
        String testdir = "test_data",
                traindir = "training_data",
                nettype = "";
        boolean train = false,
                test = true;

        for (String s : args) {
            if (s.startsWith("-c=") || s.startsWith("-charset=")) {
                s = s.replace("-charset=", "");
                s = s.replace("-c=", "");

                if (s.contains("a")) {
                    for (char c = 'a'; c <= 'z'; c++) {
                        classes.add(String.valueOf(c) + "_");
                    }
                }
                if (s.contains("A")) {
                    for (char c = 'A'; c <= 'Z'; c++) {
                        classes.add(String.valueOf(c));
                    }
                }
                if (s.contains("0")) {
                    for (char c = '0'; c <= '9'; c++) {
                        classes.add(String.valueOf(c));
                    }
                }
            } else if (s.startsWith("-testdir=")) {
                s = s.replace("-testdir=", "");
                testdir = s;
            } else if (s.startsWith("-nettype=")) {
                s = s.replace("-nettype=", "");
                nettype = s;
            } else if (s.startsWith("-traindir=")) {
                s = s.replace("-traindir=", "");
                traindir = s;
            } else if (s.startsWith("-train=")) {
                s = s.replace("-train=", "");
                if (s.matches("yes")) {
                    train = true;
                }
            } else if (s.startsWith("-test=")) {
                s = s.replace("-test=", "");
                if (s.matches("no")) {
                    test = false;
                }
            }
        }

        if (classes.isEmpty()) {

            for (char c = 'a'; c <= 'z'; c++) {
                classes.add(String.valueOf(c) + "_");
            }
            for (char c = 'A'; c <= 'Z'; c++) {
                classes.add(String.valueOf(c));
            }
            for (char c = '0'; c <= '9'; c++) {
                classes.add(String.valueOf(c));
            }

        }

        if (train) {
            Train training = new Train(classes);
            training.run(nettype, testdir);
        }

        if (test) {
            for (String symbol : classes) {
                Test t = new Test();
                for (String classed : classes) {
                    t.run(symbol, classed, nettype, testdir);
                }
                t.accuracy(symbol);
            }
        }
        
        
    }
}
